package com.gjy.datetime.time;

import com.gjy.util.DatetimeUtil;
import org.junit.jupiter.api.Test;

import java.time.Clock;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-31 13:47:20
 */
public class LocalDateTest {

    @Test
    public void test4() {
        LocalDateTime firstDayOfMonth = DatetimeUtil.firstDayOfMonth(LocalDateTime.now());
        LocalDateTime lastDayOfMonth = DatetimeUtil.lastDayOfMonth(LocalDateTime.now());
        System.out.println("firstDayOfMonth = " + firstDayOfMonth);
        System.out.println("lastDayOfMonth = " + lastDayOfMonth);
    }

    @Test
    public void test3() {
        Clock clock = Clock.systemDefaultZone();
        LocalDateTime with = LocalDateTime.now(clock).with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("with = " + with);
        System.out.println("clock = " + clock);
    }

    @Test
    public void test2() {
        LocalDate now = LocalDate.of(2022, 2, 3);
        System.out.println("now.with(TemporalAdjusters.firstDayOfMonth()) = " + now.with(TemporalAdjusters.firstDayOfMonth()));
        System.out.println("now.with(TemporalAdjusters.lastDayOfMonth()) = " + now.with(TemporalAdjusters.lastDayOfMonth()));
    }

    @Test
    public void test1() {
        LocalDate now = LocalDate.now();

        LocalDate l2 = now.plusMonths(1);
        System.out.println("now.plusMonths(1) = " + l2);
        LocalDate l3 = l2.plusMonths(1);
        System.out.println("now.plusMonths(1) = " + l3);
        LocalDate l4 = l3.plusMonths(1);
        System.out.println("now.plusMonths(1) = " + l4);
        LocalDate l5 = l4.plusMonths(1);
        System.out.println("now.plusMonths(1) = " + l5);

    }
}
